<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .grandfather{
            width: 300px;
            height: 300px;
            background: purple;
        }
        .father{
            width: 200px;
            height: 200px;
            background: gold;
            position: relative;
        }
        .son{
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            left: 0px;
            top: 400px;
        }
    </style>
    <script src="../JS/jquery-1.12.4.min.js"></script>
    <script>
        $(function () {
            // var $son = $('.son');
            // $son.click(function () {
            //     alert(1);
            // })
            $('.son').click(function () {
                alert(1);
                // 阻止事件冒泡的简单写法
                return false;
            });
            // 父级阻止事件冒泡
            $('.father').click(function (event) {
                alert(2);
                // 阻止事件冒泡的完整写法
                event.stopPropagation();
            });
            $('.grandfather').click(function () {
                alert(3);
            });
            // $(document) 代表顶级标签
            $(document).click(function () {
                alert(4);
            });
        })
    </script>
</head>
<body>
    <!-- .grangdfather>.father>.son -->
    <div class="grandfather">
        <div class="father">
            <div class="son"></div>
        </div>
    </div>
</body>
</html>